package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.entity.DiseaseInfo;
import com.ruoyi.system.mapper.DiseaseInfoMapper;
import com.ruoyi.system.service.DiseaseInfoService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author ruochen
* @description 针对表【disease_info(病情信息表)】的数据库操作Service实现
* @createDate 2023-11-19 20:46:44
*/
@Service
public class DiseaseInfoServiceImpl extends ServiceImpl<DiseaseInfoMapper, DiseaseInfo>
    implements DiseaseInfoService {


    @Override
    public List<DiseaseInfo> getDiseaseInfoByGlPeopleId(Long userId) {
        LambdaQueryWrapper<DiseaseInfo> diseaseInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        diseaseInfoLambdaQueryWrapper.eq(DiseaseInfo::getUserId,userId);
        // 按照创建时间倒序排列
        diseaseInfoLambdaQueryWrapper.orderByDesc(DiseaseInfo::getCreateTime);
        List<DiseaseInfo> diseaseInfos = this.list(diseaseInfoLambdaQueryWrapper);
        if (diseaseInfos != null && diseaseInfos.size() > 0) {
            return diseaseInfos;
        }else {
            throw new RuntimeException("未查询到该用户的病情信息");
        }
    }

    @Override
    public List<DiseaseInfo> getDiseaseInfoList(DiseaseInfo diseaseInfo) {

        LambdaQueryWrapper<DiseaseInfo> diseaseInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        //诊断日期倒序排列
        diseaseInfoLambdaQueryWrapper.orderByDesc(DiseaseInfo::getDiagnosisDate);

        if (diseaseInfo.getUserId()!=null){
            diseaseInfoLambdaQueryWrapper.eq(DiseaseInfo::getUserId,diseaseInfo.getUserId());
        }
        if (diseaseInfo.getDiseaseType()!=null){
            diseaseInfoLambdaQueryWrapper.eq(DiseaseInfo::getDiseaseType,diseaseInfo.getDiseaseType());
        }
        if (diseaseInfo.getDiseaseStage()!=null){
            diseaseInfoLambdaQueryWrapper.eq(DiseaseInfo::getDiseaseStage,diseaseInfo.getDiseaseStage());
        }
        if (diseaseInfo.getDiagnosisDate()!=null){
            diseaseInfoLambdaQueryWrapper.eq(DiseaseInfo::getDiagnosisDate,diseaseInfo.getDiagnosisDate());
        }

        return this.list(diseaseInfoLambdaQueryWrapper);
    }
}




